// https://vite.dev/config/
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import path from 'path'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve:{
    alias:{// 配置路径别名
      '@':path.resolve(__dirname,'src')
    }
  },
  // 配置跨域
  server: {
    proxy: {
      // 精确匹配/api前缀的请求
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
        // 代理websocket
        ws: true,
        // 确保在浏览器中显示正确的错误信息
        configure: (proxy, options) => {
          proxy.on('error', (err, req, res) => {
            console.log('Proxy error:', err)
          })
        }
      }
    }
  }
})
